﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Framework;

namespace TjZheng.Controls
{
    public class QueryCondition
    {
        public string EqualCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}={1}", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }

        public string NotEqualCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}<>'{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>{1}", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }

        public string GreaterThanCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}>'{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}>{1}", QueryField, QueryValue);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>{1}", QueryField, QueryValue);
                    break;

            }
            return objCondition;
        }

        public string LessThanCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}<'{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}<{1}", QueryField, QueryValue);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>{1}", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }

        public string GreaterEqualCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}>='{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}>={1}", QueryField, QueryValue);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>{1}", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }

        public string LessEqualCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}<='{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}<={1}", QueryField, QueryValue);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>{1}", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }

        public string ContainCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0} like '%{1}%'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}={1}", QueryField, QueryValue);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }

        public string StartWithCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0} like '{1}%'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}={1}", QueryField, QueryValue);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }

        public string EndWithCondition(string QueryField, string QueryValue, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            if (QueryValue.IsNull())
            {
                return objCondition;
            }
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0} like '%{1}'", QueryField, QueryValue);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}={1}", QueryField, QueryValue);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}='{1}'", QueryField, QueryValue);
                    break;
            }
            return objCondition;
        }
    }
}
